package com.hn.springcloud.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * hanni
 * 2019/2/12 0012
 * 20:28
 */
@Configuration
public class TestConfig {

    @Bean
    @LoadBalanced //开启负载均衡
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    //会覆盖之前的负载均衡算法
    @Bean
    public IRule balanceRule(){

        //类中的负载均衡算法
        //return new RandomRule();

        //自定义的负载均衡算法
        return new MyBalanceRule();
    }


}
